package com.cj.pj.sys.controller;

import com.cj.pj.sys.common.pojo.JsonResult;
import com.cj.pj.sys.service.SysUserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SysUserController {
    @Autowired
    SysUserService sysUserService;

    @RequestMapping("user/doFindPageObjects")
    public JsonResult doFindPageObjects(String username,int pageCurrent){
        return new JsonResult(sysUserService.getPageObject(username, pageCurrent));
    }

    @RequestMapping("user/doValidById")
    public JsonResult changeValid(int id ,int valid){
        return new JsonResult(sysUserService.changeValid(id,valid));
    }

    @RequestMapping("user/doFindObjectById")
    public JsonResult findObjectById(Integer id){
        return new JsonResult(sysUserService.findObjectById(id));
    }

    @RequestMapping("/user/login")
    public JsonResult login(String username,String password){
        Subject subject= SecurityUtils.getSubject();

        UsernamePasswordToken token=new UsernamePasswordToken(username,password);
        subject.login(token);
        return new JsonResult("登录成功");


    }
}
